<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>07 demo</title>
</head>

<body>
    <p style="font-family: Kaiti;font-size: large;">tip: 请打开控制台，结合源代码理解</p>

    <script>
        setTimeout(function () {
            console.log("这是一个在 2s 后执行的定时器")
        }, 2000)

        var name = "global";  // 全局变量

        var user = {
            name: "itbaizhan",
            getName: function () {
                var that = this;
                setTimeout(function () {
                    console.log(that.name);
                }, 1000)
            }
        };
        user.getName();

        var user = {
            name: "itbaizhan",
            getName: function () {
                setTimeout(function () {
                    console.log(this.name);
                    // 查看长度
                    console.log(this.name.length);
                    console.log(typeof this.name);
                }, 1000)
            }
        };
        user.getName();
    </script>
</body>

</html>